<template>
	<view class="container">
		<fu-navbar title="选择分类" bgColor="#0f68f0" color="#fff" isBackText></fu-navbar>
		<view class="flex padding-tb-16 padding-lr-24 bg-f margin-t-32" @click="handleItem()">
			<image src="../../../static/images/icon45.png" mode="widthFix" style="width: 40rpx;margin-right: 12rpx;"></image>
			<view class="fs-32 text-bold">全部知识</view>
		</view>
		<view class="padding-lr-24 padding-tb-32 fs-36 text-bold">故障分类</view>
		<view class="bg-f">
			<view class="padding-lr-24 padding-tb-16 flex align-end" v-for="(item, index) in list" :key="index" @click="handleItem(item)">
				<image src="../../../static/images/icon46.png" mode="widthFix" style="width: 40rpx;margin-right: 12rpx;"></image>
				<view class="fs-28">{{getDictName('TYPE_REP_MAINTENANCE',item.faultType)}}</view>
				<!-- <view class="fs-26 margin-l-12 color-9">{{item.count}}</view> -->
			</view>
		</view>
		<fu-empty-ui v-if="list.length == 0 && isInit"></fu-empty-ui>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				isInit: false,
				dictTypeMap: []
			}
		},
		onLoad() {
			this.getSelectDictByDictTypeMap()
			this.getList()
		},
		methods: {
			getDictName(dictType, value) {
				const dictItems = this.dictTypeMap[dictType];
				if (!dictItems) return "-";
				const item = dictItems.find((item) => item.dictValue == value);
				return item ? item.dictName : "-";
			},
			getSelectDictByDictTypeMap() {
				const dictTypeCode = "TYPE_REP_MAINTENANCE"
				this.$api.post(global.apiUrls.selectDictByDictTypeMap, {
					dictTypeCode
				}).then(({
					data
				}) => {
					this.dictTypeMap = data.info
				}).catch(error => {
					console.log(error)
				})
			},
			async getList() {
				await uni.request({
					url: 'http://150.158.40.124:9001/apiv1/knowledge/base/queryModelList',
					method: 'POST',
					header: {
						'Content-Type': 'application/json',
						'Authorization': global.token || ''
					},
					data: {
						modelCode: 'com.xframe.domain.knowledgeBase.VFaultCount',
						queryKey: 'default',
						ver: "v1",
						refList: ["ALL"],
						sortDir: 'DESC',
						sortName: 'updateTime',
						pageIndex: this.page,
						pageSize: 10,
						recordCountFlag: 'true'
					},
					success: res => {
						if (res.data.code == 200) {
							let data = res.data.data
							this.list = data
						}
						this.isInit = true;
						uni.stopPullDownRefresh();
					},
					complete() {
						uni.stopPullDownRefresh();
					}
				})
			},
			handleItem(e) {
				let data;
				if (e) {
					e.dictName = this.getDictName('TYPE_REP_MAINTENANCE',e.faultType)
					data = e
				} else {
					data = '全部知识'
				}
				uni.$emit('selectClass', data)
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		min-height: 100vh;
		background-color: #f3f5f8;
	}
</style>